Shop OBEX P1 Docs P2 Docs Learn Events
Using Visual Studio as GCC project editor (?) — Parallax Forums

Using Visual Studio as GCC project editor (?)

RaymanRayman Posts: 14,826
edited 2012-09-20 22:01 in Propeller 1
GCC crew may take offense, but I'm used to working in Visual Studio...
So, I just took a stab at seeing if I can use Visual Studio to edit Prop GCC code...

One cool thing I just found googling to this page:
http://www.c-sharpcorner.com/uploadfile/rmcochran/running-the-command-prompt-from-visual-studio-tools-menu/

is adding an external tool to the "Tools" menu like this:
VS_ExtTool.png


I'm pretty sure this is going to work because I just happened to have "calc.c" open (from the demos) when I tried it.
I thought I was going to have to create a "build.bat" file, but it turned out (to my surprise) that one already existed:
VS_ExtTool_Output.png


Not only did it compile, but it tried to load too.
469 x 465 - 24K
742 x 212 - 10K

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-08-19 06:42
    That looks interesting.

    So many things coming together at the moment. I'm playing around with translating the object description file for C# into spin. It is a bit complicated as it involves translating an object oriented language into a non object oriented one, but it is quite possible to do. But translating C# into C++ is more plausible, and I think averagejoe is very close with the cache driver for a touchscreen.

    It would be nifty to be able to write and debug C# code on the PC prior to running the same code on the propeller. I can see several ways to do that.

    Keep experimenting Rayman, this looks great!
  • Heater.Heater. Posts: 21,230
    edited 2012-08-19 07:21
    This is so wrong:)
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-19 08:09
    Heater. wrote: »
    This is so wrong:)
    +1
  • jazzedjazzed Posts: 11,803
    edited 2012-08-19 10:04
    No offense. You got very lucky though. That may be the only project in the demos that has a build.bat.
  • RaymanRayman Posts: 14,826
    edited 2012-09-03 05:21
    I just noticed today that Visual Studio looks like a popular option for Arduino users...
    There are several ways to do it apparently...
    This page describes how to do it with the free Express version of VC++:
    http://arduino.cc/playground/Code/VisualCPPExpress

    The one thing that makes it work is a "Use External Editor" option in the Arduino IDE.
    So, maybe adding this option to "Simple IDE" would let people do something similar...

    On second thought, I like the way I did it earlier better.
    It's nice to have all the files together in Visual Studio so I can search through all the project files...
  • jac_goudsmitjac_goudsmit Posts: 418
    edited 2012-09-03 12:27
    I work with Visual Studio on a daily basis, about 60% with Visual Studio 6 and about 40% with Visual Studio 2010.

    Setting up a Visual Studio project for a Propeller project is certainly possible but it turns into a real hassle when you have big projects or you want to either offer your code to use by others, or you want to use code that others wrote.

    The problem is that you have to change the compiler options for each and every .c file to use the Propeller compiler, and there's no easy way to do it automatically, so it gets tedious. Using a batch file (or even better: a make file) helps, but the bottom line is: to me it's only worth leaving SimpleIDE if I need to do something in the editor that SIDE won't do, or is bad at, like search and replace. And in most of those cases, I'd rather open the file in an editor such as Notepad++ than having to start Visual Studio.

    ===Jac
  • RaymanRayman Posts: 14,826
    edited 2012-09-03 12:45
    Here's a post of mine from another thread that shows how you can easily compile under Visual Studio:

    Ok, I tried out the forumists/jazzed calc example in Visual Studio and I think it works with some minor changes...

    First, I had to disable use of precompiled headers in the project settings:
    Attachment not found.

    Second, I had to change unistd.h to Windows.h like this:
    //#include <unistd.h>
    #include <Windows.h>
    

    Then, had to change sleep to Sleep like this:
    //sleep(1);
    Sleep(1000);      // give terminal time to start
    //RJA Changed from sleep and from 1 to 1000
    

    It then compiles and runs in a DOS window in full Debug mode with any breakpoints you want:
    Attachment not found.

    Since Visual Studio Express is a free download, this may offer people a way to test out and debug GCC code...
  • RaymanRayman Posts: 14,826
    edited 2012-09-03 12:50
    Jac, Visual Studio offers so many things that I'm very reluctant to leave it...
    Automatic code completion, context sensitive help, find in files, are just a few.
    Plus, I'm very used to the colors and other choices just don't look right to me...

    Sharing with others not using Visual Studio is a problem though. Might not be a huge problem though.

    BTW, if you read the first post, you can see how I compiled with PropGCC inside Visual Studio very easily...
  • ersmithersmith Posts: 6,095
    edited 2012-09-04 05:31
    What you've described Rayman is how to get Visual Studio to compile the forumists/jazzed calc example as a Windows executable -- that's why for example #include <unistd.h> has to be changed to #include <Windows.h>.

    I think what others in the thread are interested in is using Visual Studio as an IDE but compiling with PropGCC to produce a Propeller executable. That's possible, but it seems it's still awkward.

    Eric
  • BatangBatang Posts: 234
    edited 2012-09-04 06:36
  • RaymanRayman Posts: 14,826
    edited 2012-09-04 10:09
    Eric, the top post in this thread descibes how to easily compile and load from within Visual Studio by creating an "External Tool"...
    (later, I posted about how to run it in Windows because that's nice too...)

    Batang, that looks like it might be a way to make this work even better...
  • RaymanRayman Posts: 14,826
    edited 2012-09-15 11:03
    Batang, I just tried out a Makefile project mode in Visual Studio 2010... This seems to work very nicely!
    I created a build.bat file and then set the "build command line" to "build".
    Was also able to specify a PropGCC include path so that clicking on "propeller.h" opens it up...

    As an added bonus, I can edit embedded bmp files in the editor. Although not many people are likely to use this feature...

    Anyway, I think this is even better than that other way. Now, when I hit the green "Start" button, it compiles and then loads.

    The interactive terminal mode option for the loader seems to mess up Visual Studio though... Have to look into that...
  • jazzedjazzed Posts: 11,803
    edited 2012-09-16 11:16
    Rayman wrote: »
    The interactive terminal mode option for the loader seems to mess up Visual Studio though... Have to look into that...
    This is a common problem with other IDE's too. Often the terminal is read-only because of the "tool window" and the loader process must be killed. The problem is not with the loader, just the way the IDE treats it. Seems like one could "start" the loader in a command window from the batch file and solve the issue. See this for "start" help http://www.computerhope.com/batch.htm#03
  • RaymanRayman Posts: 14,826
    edited 2012-09-16 12:19
    It's getting closer to what I want now...
    Build from the menu runs the build.bat file that runs propeller-elf-c++ and then propeller-elf-size to report the program size
    The green run button now builds and then runs propeller-load.exe with options you can specify

    Only slight issue left is getting intellisense to not put red squigglies all over...
    Seems there are a lot of things that are not defined...
    Main culprit is uint32_t, which it doesn't seem to know because neither _INT_SIZE nor _LONG_SIZE are defined...

    Also it marks things like DIRB, waitcnt and cogstop as errors.
    I think there, it doesn't know how to handle the definition:
    extern _COGMEM volatile unsigned int _PAR __asm__("PAR");

    So, I have to decide if I should define things myself, learn to ignore the squigglies, or find a way to get intellisense to ignore these perceived errors...


  • jazzedjazzed Posts: 11,803
    edited 2012-09-16 23:38
    Rayman wrote: »

    Main culprit is uint32_t, which it doesn't seem to know because neither _INT_SIZE nor _LONG_SIZE are defined...

    Squiggles are up to the language processor. Eclipse has similar issues, and needs a plugin to do the right thing.

    The alternative to uint32_t is unsigned int or unsigned long on Propeller GCC, but not necessarily on other processors or compilers .... Want to change 1 line of code or 1000?
  • RaymanRayman Posts: 14,826
    edited 2012-09-17 03:57
    Seems I can fix that issue by adding "define _INT_SIZE 4" to Propeller.h
  • jazzedjazzed Posts: 11,803
    edited 2012-09-17 14:19
    Is that a request? Are there other simple convenience macros that may help?
  • RaymanRayman Posts: 14,826
    edited 2012-09-17 15:24
    I'm not actually sure what the best thing to do is... Defining INT_SIZE appears to clear up most of the problem.
    I can probably live with the other syntax problems if there's no easy solution...
  • jazzedjazzed Posts: 11,803
    edited 2012-09-17 16:45
    Rayman wrote: »
    I'm not actually sure what the best thing to do is... Defining INT_SIZE appears to clear up most of the problem.
    I can probably live with the other syntax problems if there's no easy solution...

    Some things like PAR, waitcnt, etc... are just Propeller specific. Some VisualStudio thing will have to be tweaked to get around such issues.

    Looks like _INT_SIZE is defined in compiler.h which is included in stdint.h .... propeller.h includes stdint.h. Given that, I'm not sure I understand the issue with _INT_SIZE.
  • RaymanRayman Posts: 14,826
    edited 2012-09-17 16:57
    Ok, that was just the tip I needed...
    I see in compiler.h that __GNUC__ must be defined by the gcc compiler that Visual Studio doesn't know about.
    So, all I've done is use #if, #else, #endif defines to define things the way that don't get flagged as errors...
    Did this in cog.h too and now the only squigglies I have are on waitcnt and cognew. But, I think I know how to fix those up too now...
  • ersmithersmith Posts: 6,095
    edited 2012-09-17 17:03
    jazzed wrote: »
    Looks like _INT_SIZE is defined in compiler.h which is included in stdint.h .... propeller.h includes stdint.h. Given that, I'm not sure I understand the issue with _INT_SIZE.

    _INT_SIZE is inside #ifdef __GNUC__, because (in theory) the sizes could be compiler dependent. I guess __GNUC__ is not defined inside Visual Studio. We could provide default sizes in compiler.h if no compiler symbols are recognized.
  • RaymanRayman Posts: 14,826
    edited 2012-09-17 18:06
    I'm not sure I'd want you to change anything yet... It appears pretty easy to fix things up on this end...
    I have one code squiggly free now with this minor addition to compiler.h
    #if defined(__GNUC__)
    ...
    #else
    
      //RJA
    #define _INT_SIZE  4
    #define __builtin_propeller_waitcnt(a,b)
    #define __builtin_propeller_cogstop((a))
    #define __builtin_propeller_coginit(a,b,c)
    
    #error "compiler not yet supported"
    

    and a similar thing in cog.h
    #else
    //RJA
    extern unsigned int _PAR;//__asm("PAR");
    extern unsigned int _CNT;// __asm("CNT");
    extern unsigned int _INA;// __asm__("INA");
    extern unsigned int _INB;// __asm__("INB");
    extern unsigned int _OUTA;// __asm__("OUTA");
    extern unsigned int _OUTB;// __asm__("OUTB");
    extern unsigned int _DIRA;// __asm__("DIRA");
    extern unsigned int _DIRB;// __asm__("DIRB");
    extern unsigned int _CTRA;// __asm__("CTRA");
    extern unsigned int _CTRB;// __asm__("CTRB");
    extern unsigned int _FRQA;// __asm__("FRQA");
    extern unsigned int _FRQB;// __asm__("FRQB");
    extern unsigned int _PHSA;// __asm__("PHSA");
    extern unsigned int _PHSB;// __asm__("PHSB");
    extern unsigned int _VCFG;// __asm__("VCFG");
    extern unsigned int _VSCL;// __asm__("VSCL");
    #endif
    
  • RaymanRayman Posts: 14,826
    edited 2012-09-20 18:05
    Perhaps one way to make it easy to go back and forth between Visual Studio and SimpleIDE is to find or make a
    command line tool that will build the project based on settings in a .side file.

    The .side project files seem to have all the necessary info to build a project with...
    The file is just plain text and I think I can decipher the format...
  • jazzedjazzed Posts: 11,803
    edited 2012-09-20 22:01
    Rayman wrote: »
    Perhaps one way to make it easy to go back and forth between Visual Studio and SimpleIDE is to find or make a
    command line tool that will build the project based on settings in a .side file.

    True. You can find out more about what SimpleIDE does with files in the UserGuide - you've probably seen that by now. There is also a BuildC class in the SimpleIDE repository that can be "ported" for making a stand-alone app.

    See http://code.google.com/p/propside/source/browse/propside/buildc.cpp?name=spinside and http://code.google.com/p/propside/source/browse/propside/buildc.h?name=spinside
    The BuildC class extends the abstract Build class http://code.google.com/p/propside/source/browse/propside/build.cpp?name=spinside and http://code.google.com/p/propside/source/browse/propside/build.h?name=spinside Unfortunately there are lots of hooks into the SimpleIDE infrastructure, but they should be easy to trim out.

    There is another initiative I'm studying for Parallax to make SimpleIDE generate intermediate files that can be used in Visual Studio or other IDE's like Geany, Eclipse, Netbeans, etc.... It's part of a broader simplification effort. Once I have more concrete progress, I'll describe it all.
Sign In or Register to comment.