X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Fcall_str_example.c;h=76b2693f760fd71c2125a1d204ea1adb9522bc76;hb=91ba1eff56d080774e7e40c31c6570344d23b3d2;hp=d275d07e2daa7a8812123ef85de6a69786371b74;hpb=fea2a862b08a06f74d199881ce9aed7753d15da9;p=libfirm diff --git a/testprograms/call_str_example.c b/testprograms/call_str_example.c index d275d07e2..76b2693f7 100644 --- a/testprograms/call_str_example.c +++ b/testprograms/call_str_example.c @@ -1,10 +1,14 @@ -/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe -* All rights reserved. -* -* Authors: Christian Schaefer, Goetz Lindenmaier -* -* testprogram. -*/ +/* + * Project: libFIRM + * File name: testprograms/call_str_example.c + * Purpose: Shows representation of constant string. + * Author: Goetz Lindenmaier + * Modified by: + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 1999-2003 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ # include # include @@ -14,16 +18,16 @@ # include "firm.h" /** -* This file constructs the ir for the following pseudo-program: -* -* void f(char *); -* -* void CALL_STR_EXAMPLE_main () { - f("Hello World\n"); -* } -* -* This program shall demonstrate how to represent string constants. -**/ + * This file constructs the ir for the following pseudo-program: + * + * void f(char *); + * + * void CALL_STR_EXAMPLE_main () { + * f("Hello World\n"); + * } + * + * This program demonstrates how to represent string constants. + */ int main(int argc, char **argv) { @@ -44,14 +48,16 @@ int main(int argc, char **argv) init_firm (NULL); /* An unsinged 8 bit type */ - U8 = new_type_primitive (id_from_str("char", 4), mode_Bu); + U8 = new_type_primitive (new_id_from_chars("char", 4), mode_Bu); /* An array containing unsigned 8 bit elements. */ - U8array = new_type_array (id_from_str ("char_arr", 8), 1, U8); - string_ptr = new_type_pointer (id_from_str ("ptr_to_string", 13), U8array); + U8array = new_type_array (new_id_from_chars("char_arr", 8), 1, U8); + set_array_lower_bound_int(U8array, 0, 0); + + string_ptr = new_type_pointer (new_id_from_chars ("ptr_to_string", 13), U8array, mode_P); /* Make a global entity that represents the constant String. */ const_str = new_entity(get_glob_type(), new_id_from_str("constStr"), U8array); - set_entity_variability(const_str, constant); + set_entity_variability(const_str, variability_constant); for (i = 0; i < strlen(str); i++) { tarval *val = new_tarval_from_long(str[i], mode_Bu); ir_node *con = new_Const(mode_Bu, val); @@ -68,7 +74,7 @@ int main(int argc, char **argv) #define NRARGS 0 #define NRES 0 owner = get_glob_type(); - proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), + proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)), NRARGS, NRES); /* Make type information for called method which also belongs to the @@ -77,14 +83,14 @@ int main(int argc, char **argv) #define F_NRARGS 1 #define F_NRES 0 owner = get_glob_type(); - proc_called = new_type_method(id_from_str(F_METHODNAME, strlen(F_METHODNAME)), + proc_called = new_type_method(new_id_from_chars(F_METHODNAME, strlen(F_METHODNAME)), F_NRARGS, F_NRES); set_method_param_type(proc_called, 0, string_ptr); /* Make the entity for main needed for a correct ir_graph. */ #define ENTITYNAME "CALL_STR_EXAMPLE_main" - ent = new_entity (owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), + ent = new_entity (owner, new_id_from_chars (ENTITYNAME, strlen(ENTITYNAME)), proc_main); /* Generates the basic graph for the method represented by entity ent, that @@ -95,12 +101,14 @@ int main(int argc, char **argv) irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS); /* get the pointer to the string constant */ - str_addr = new_Const(mode_P, new_tarval_from_entity(const_str, mode_P)); + symconst_symbol sym; + sym.entity_p = const_str; + str_addr = new_SymConst(sym, symconst_addr_ent); /* get the pointer to the procedure from the class type */ /* this is how a pointer to be fixed by the linker is represented. */ - proc_ptr = new_SymConst ((type_or_id_p)id_from_str (F_METHODNAME, strlen(F_METHODNAME)), - linkage_ptr_info); + sym.ident_p = new_id_from_str (F_METHODNAME); + proc_ptr = new_SymConst (sym, symconst_addr_name); /* call procedure set_a, first built array with parameters */ { @@ -115,15 +123,15 @@ int main(int argc, char **argv) x = new_Return (get_store(), 0, NULL); /* Now we generated all instructions for this block and all its predecessor blocks * so we can mature it. */ - mature_block (get_irg_current_block(irg)); + mature_immBlock (get_irg_current_block(irg)); /* This adds the in edge of the end block which originates at the return statement. * The return node passes controlflow to the end block. */ - add_in_edge (get_irg_end_block(irg), x); + add_immBlock_pred (get_irg_end_block(irg), x); /* Now we can mature the end block as all it's predecessors are known. */ - mature_block (get_irg_end_block(irg)); + mature_immBlock (get_irg_end_block(irg)); - finalize_cons (irg); + irg_finalize_cons (irg); printf("Optimizing ...\n"); dead_node_elimination(irg); @@ -132,8 +140,9 @@ int main(int argc, char **argv) irg_vrfy(irg); printf("Done building the graph. Dumping it.\n"); - dump_ir_block_graph (irg); - dump_all_types(); + char *dump_file_suffix = ""; + dump_ir_block_graph (irg, dump_file_suffix); + dump_all_types(dump_file_suffix); printf("Use xvcg to view this graph:\n"); printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");